package com.poetry.vup.works.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.poetry.vup.common.entity.works.VupExhibitionDO;
import com.poetry.vup.works.domain.VupDetialVO;
import com.poetry.vup.works.domain.VupExhibitionVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VupExhibitionMapper extends BaseMapper<VupExhibitionDO> {

    @Select("<script>"+
            "SELECT " +
            "t1.id,"+
            "t1.vup_face," +
            "t1.vup_sign," +
            "t1.vup_name," +
            "t1.vup_cover," +
            "t1.mid_id FROM " +
            "vup_exhibition t1 " +
            "where 1=1 "+
            "ORDER BY t1.gmt_create DESC " +
            "LIMIT #{offset}, #{pageSize}"+
            "</script>")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "vup_face", property = "vupFace"),
            @Result(column = "vup_sign", property = "vupSign"),
            @Result(column = "vup_name", property = "vupName"),
            @Result(column = "vup_cover", property = "vupCover"),
            @Result(column = "mid_id", property = "midId")
    })
    List<VupExhibitionVO> findAllVup(@Param("offset") int offset, @Param("pageSize") int pageSize);

    @Select("SELECT count(*) FROM vup_exhibition")
    Long getCount();

    @Select("SELECT t2.personal_introduction," +
            "t2.id,t1.vup_cover " +
            "FROM vup_exhibition t1 " +
            "INNER JOIN vup_user_info t2 " +
            "ON t2.id = t1.user_id " +
            "WHERE t1.id = #{id}")
    @Results({
            @Result(column = "id", property = "userId"),
            @Result(column = "vup_cover", property = "vupCover"),
            @Result(column = "personal_introduction", property = "vupSign")
    })
    VupDetialVO findDetail(@Param("id") Long id);

    @Select("<script>"+
            "SELECT " +
            "t1.id,"+
            "t1.vup_face," +
            "t1.vup_sign," +
            "t1.vup_name," +
            "t1.vup_cover," +
            "t1.mid_id FROM " +
            "vup_exhibition t1 " +
            "where 1=1 "+
            "ORDER BY t1.gmt_create DESC " +
            "</script>")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "vup_face", property = "vupFace"),
            @Result(column = "vup_sign", property = "vupSign"),
            @Result(column = "vup_name", property = "vupName"),
            @Result(column = "vup_cover", property = "vupCover"),
            @Result(column = "mid_id", property = "midId")
    })
    List<VupExhibitionVO> findList();

    @Select("<script>"+
            "SELECT " +
            "t1.id,"+
            "t1.vup_face," +
            "t1.vup_sign," +
            "t1.vup_name," +
            "t1.vup_cover," +
            "t1.mid_id FROM " +
            "vup_exhibition t1 " +
            "where 1=1 " +
            "<if test =\"name != null and name != ''\"> " +
            "AND t1.vup_name like '%${name}%' "+
            "</if> "+
            "</script>")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "vup_face", property = "vupFace"),
            @Result(column = "vup_sign", property = "vupSign"),
            @Result(column = "vup_name", property = "vupName"),
            @Result(column = "vup_cover", property = "vupCover"),
            @Result(column = "mid_id", property = "midId")
    })
    List<VupExhibitionDO> findVupName(@Param("name") String name);

    /**
     * 查找banner页
     */
    @Select("<script>" +
            "SELECT id," +
            "vup_cover," +
            "vup_name," +
            "vup_face," +
            "vup_sign," +
            "mid_id FROM " +
            "vup_exhibition " +
            "ORDER BY gmt_create DESC"+
            "</script>")
    void findBanner();
}
